package org.intelligentsia.keystone.boot;

import java.util.Locale;

/**
 * Based on value found : http://lopica.sourceforge.net/os.html.
 * The purpose of this class if to detemine which plateform is used.
 * 
 * @author <a href="mailto:jguibert@intelligents-ia.com" >Jerome Guibert</a>
 */
public class OSDetector {

	public enum Name {

		Linux, Mac, Windows
	}

	private static final Name	name;

	static {
		final String os = System.getProperty("os.name", "").toLowerCase(Locale.getDefault());
		if (os.startsWith("windows") || os.contains("nt")) {
			name = Name.Windows;
		} else if (os.startsWith("mac")) {
			name = Name.Mac;
		} else {
			name = Name.Linux;
		}
	}

	/**
	 * @return true if linux is current plateform.
	 */
	public static boolean isLinux() {
		return Name.Linux.equals(OSDetector.name);
	}

	/**
	 * @return true if windows is current plateform.
	 */
	public static boolean isWindoww() {
		return Name.Windows.equals(OSDetector.name);
	}

	/**
	 * @return true if mac is current plateform.
	 */
	public static boolean isMac() {
		return Name.Mac.equals(OSDetector.name);
	}

	/**
	 * @return current plateform name.
	 */
	public static Name getName() {
		return OSDetector.name;
	}
}
